package com.itheima.arraylist;

import java.util.ArrayList;
import java.util.Scanner;

public class FoodOperator {
    // 存放食物的集合
    private ArrayList<Food> foodList = new ArrayList<>();

    public void addFood() {
       Food food = new Food();


        Scanner scanner = new Scanner(System.in);
        System.out.println("请输入食物名称：");
        String name = scanner.next();
        food.setName(name);

        System.out.println("请输入菜品价格");
        double price = scanner.nextDouble();
        food.setPrice(price);

        System.out.println("请输入菜品描述");
        String desc = scanner.next();
        food.setDesc(desc);

        foodList.add(food);
        System.out.println("添加成功");
    }
    public void showAllFoods() {
        /*for (Food food : foodList) {
            System.out.println(food);
        }*/
        if (foodList.isEmpty()) {
            System.out.println("暂无食物");
            return;
        }
        for (int i = 0; i < foodList.size(); i++) {
           Food food = foodList.get(i);
           System.out.println(food.getName());
           System.out.println(food.getPrice());
           System.out.println(food.getDesc());
           System.out.println("******");
        }
    }

    public void start(){
        while (true) {
            System.out.println("请选择功能");
            System.out.println("1 添加食物");
            System.out.println("2 查看所有食物");
            System.out.println("3 退出");
            Scanner scanner = new Scanner(System.in);
            System.out.println("请输入你的选择：");
            String choice = scanner.next();
            switch (choice) {
                case "1":
                    addFood();
                    break;
                case "2":
                    showAllFoods();
                    break;
                case "3":
                    System.out.println("退出");
                    return;
                default:
                    System.out.println("输入有误，请重新选择");
                    start();
                    break;
            }
        }
    }

}
